package thrift

import (
	"gitee.com/tietang/terrace-go/v2/example/apis"
	"gitee.com/tietang/terrace-go/v2/example/apis/thrift/gen/handlers"
	"strconv"
	"time"
)

func FromAccountCreateReq(req *handlers.AccountCreateReq) apis.AccountCreateDTO {
	dto := apis.AccountCreateDTO{
		AccountName:  req.AccountName,
		AccountType:  int(req.AccountType),
		Amount:       req.Amount,
		CurrencyCode: req.CurrencyCode,
		UserId:       req.Userid,
		Username:     req.Username,
	}
	return dto
}

func ToAccountRes(account *apis.AccountDTO) *handlers.AccountRes {
	balance, _ := strconv.ParseFloat(account.Balance.String(), 64)
	res := &handlers.AccountRes{
		AccountNo:    account.AccountNo,
		AccountName:  account.AccountName,
		AccountType:  int8(account.AccountType),
		CurrencyCode: account.CurrencyCode,
		UserId:       account.UserId,
		Username:     account.Username,
		Balance:      balance,
		Status:       int8(account.Status),
		CreatedAt:    account.CreatedAt.UnixNano() / int64(time.Millisecond),
		UpdatedAt:    account.UpdatedAt.UnixNano() / int64(time.Millisecond),
	}

	return res
}
